import csv
import logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
def process_csv(input_path, output_path):
    try:
        with open(input_path, 'r', encoding='utf-8') as f_in, \
             open(output_path, 'w', encoding='utf-8', newline='') as f_out:

            reader = csv.reader(f_in)
            writer = csv.writer(f_out)
            header = next(reader)
            writer.writerow(header)

            for row in reader:
                if len(row) != 4:
                    logging.warning(f"过滤无效行: {row}")
                    continue
                try:
                    processed = [row[0]] + [f"{float(v)*100:.1f}%" for v in row[1:]]
                    writer.writerow(processed)
                except ValueError:
                    logging.error(f"数据转换错误，过滤行: {row}")
    except FileNotFoundError:
        logging.error(f"文件未找到: {input_path} 或 {output_path}")
    except Exception as e:
        logging.error(f"发生未知错误: {e}")

process_csv(r"D:\qq\price2016.csv", r"D:\qq\price2016out.csv")
print(" 处理完成！")